//
//  OPSearch.h
//  OPFramework
//
//  Created by malcom on 7/29/08.
//  Copyright 2008 malcom-mac software. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "OPBoard.h"
#import "OPPageContainer.h"
#import "OPBaseObject.h"

// OPTIONS VALUES FOR p_searchWhere PROPERTY
#define OPSearch_Where_All				@"all"			// search in all topics message body + title
#define OPSearch_Where_FirstPostOnly	@"firstpost"	// search only in first post (body+title)
#define OPSearch_Where_TitleOnly		@"titleonly"	// search only in posts titles
#define OPSearch_Where_MessageBodyOnly	@"msgonly"		// search only in bodies

// OPTIONS VALUES FOR p_orderResultBy PROPERTY
#define OPSearch_OrderRes_Time			@"t"			// by date
#define OPSearch_OrderRes_Author		@"a"			// by author
#define OPSearch_OrderRes_Forum			@"f"			// by parent forum
#define OPSearch_OrderRes_TopicTitle	@"i"			// by topic title
#define OPSearch_OrderRes_PostTitle		@"s"			// by post title

// OPTIONS VALUES FOR p_whatResult PROPERTY
#define OPSearch_WhatResult_Topics		@"topics"		// results are topics
#define OPSearch_WhatResult_Posts		@"posts"		// results are posts


/*!
 @class			OPSearch
 @abstract		OPSearch class is used to perform deep search in board posts
 @discussion	You need to instantiate OPSearch class when you need to perform a search inside board messages.
				Is possible to make more instance of this class linked to the same board.
 
 */

@interface OPSearch : OPBaseObject {
	NSMutableArray		*p_forumsToSearch;		// list of forums where you want to search (leave it empty to search inside all the board)
	NSString			*p_searchWhere;			// OPSearch_Where_All,OPSearch_Where_FirstPostOnly,OPSearch_Where_TitleOnly,OPSearch_Where_MessageBodyOnly
	NSString			*p_orderResultBy;		// OPSearch_OrderRes_Time,OPSearch_OrderRes_Author,OPSearch_OrderRes_Forum,OPSearch_OrderRes_TopicTitle,OPSearch_OrderRes_PostTitle
	BOOL				 p_orderDescending;		// standard order is descending (most recent first - 'd' or 'a' for ascending)
	int					 p_resultsToShow;		// -1 to get the complete list, or an int value to limit search results
	int					 p_limitDays;			// limit results search by days (30 days, one month is the default value)
	NSString			*p_whatResult;			// OPSearch_WhatResult_Topics,OPSearch_WhatResult_Posts
	NSNumber			*p_searchInsideTopicID; // you can specify a topic id where to limit the search
	NSString			*p_keywords;			// what are you searchoing?
	
	OPPageContainer		*p_results;				// paginated search results
}

@property (readonly) OPPageContainer *p_results;

#pragma mark INIT METHODS
/*!
    @method     initToSearchKeywords:inBoard:
    @abstract   This method allows you to make a new istance of OPSearch class with some extra parameters set in their default values.
    @discussion <#(comprehensive description)#>
*/

- (id) initToSearchKeywords:(NSString *) _keywords inBoard:(OPBoard *) _board;

- (id) initToSearch:(NSString *) _whatSearch keywords:(NSString *) _keys inBoard:(OPBoard *) _board specificTopicID:(NSNumber *) _topicID 
			limitToForums:(NSArray *) _forums searchWhere:(NSString *) _where 
			orderBy:(NSString *) _order desc:(BOOL) _desc howShow:(int) _itemsToShow limitByDays:(int) _daylimit;


#pragma mark PUBLIC METHODS
- (NSArray *) getResultsPage:(NSNumber *) _pgIdx;

#pragma mark PRIVATE METHODS
- (void) _parseSearchResultsItems:(NSArray *) _result;

@end
